package com.yx.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yx.dao.ProductInfoMapper;
import com.yx.po.ProductInfo;
import com.yx.service.ProductInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("productInfoService")
public class ProductInfoServiceImpl implements ProductInfoService {

    @Autowired
    private ProductInfoMapper productInfoMapper;

    @Override
    public PageInfo<ProductInfo> queryProductInfoAll(ProductInfo productInfo, Integer pageNum, Integer limit) {
        PageHelper.startPage(pageNum,limit);
        List<ProductInfo> productInfoList = productInfoMapper.queryProductInfoAll(productInfo);
        return new PageInfo<>(productInfoList);
    }

    @Override
    public void addBookSubmit(ProductInfo productInfo) {
        productInfoMapper.insert(productInfo);
    }

    @Override
    public ProductInfo queryProductInfoById(Integer id) {
        return productInfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public void updateBookSubmit(ProductInfo info) {
        productInfoMapper.updateByPrimaryKeySelective(info);
    }

    @Override
    public void deleteBookByIds(List<String> ids) {
        for (String id : ids){
            productInfoMapper.deleteByPrimaryKey(Integer.parseInt(id));
        }
    }

    @Override
    public List<ProductInfo> getBookCountByType() {
        return productInfoMapper.getBookCountByType();
    }
}
